Print a more useful error message when the target binary can't be removed.
authorTed Mielczarek <ted@mielczarek.org>
Wed, 27 Jul 2016 15:22:06 +0000 (11:22 -0400)
committerTed Mielczarek <ted@mielczarek.org>
Wed, 27 Jul 2016 15:22:06 +0000 (11:22 -0400)
This happens sometimes on Windows if the target is still running, and right
now cargo prints a very cryptic message:
```
$ cargo build
   Compiling sccache v0.1.0 (file:///C:/build/sccache2)
An unknown error occurred
```

With this patch we get a much more useful error:
```
$ ../cargo/target/debug/cargo build
   Compiling sccache v0.1.0 (file:///C:/build/sccache2)
error: Could not remove file: c:\build\sccache2\target\debug\sccache.exe.

To learn more, run the command again with --verbose.
```

src/cargo/ops/cargo_rustc/mod.rs

index bffb0b63f89051c8021a78352967a486043e8515..7dfa8ff45adf17120dbc496f2a5f513fff424ace 100644 (file)
@@ -258,7 +258,9 @@ fn rustc(cx: &mut Context, unit: &Unit) -> CargoResult<Work> {
         for &(ref filename, _linkable) in filenames.iter() {
             let dst = root.join(filename);
             if fs::metadata(&dst).is_ok() {
-                try!(fs::remove_file(&dst));
+                try!(fs::remove_file(&dst).chain_error(|| {
+                    human(format!("Could not remove file: {}.", dst.display()))
+                }));
             }
         }